<?

//OK HERE STARTS THE FUN BIT.
// LATER WE SEPARATE EACH OF THESE INTO FILES
// LETS START WITH THE EASY MYSQL FACTOR:

$myMysql="";
$ife="";
$drp="";
if ($currentConfig->mysql_ifexists){
	$ife=" IF NOT EXISTS";
}
if ($currentConfig->mysql_drop){
	$drp="\nDROP TABLE IF EXISTS $tp".$mod->name.";";
}
// att = BINARY/UNSIGNED/UNSIGNED ZEROFILL


$PRIMARY = "";
$UNIQUE = "";
$FULLTEXT = "";
$INDEX = "";

$myMysql .= "$drp\nCREATE TABLE$ife $tp".$mod->name."(";
foreach($mod->values->vars as $myItem){
	//print_r($myItem);
	$myMysql .= "\n\t".$myItem->name." ".$myItem->type.($myItem->length==""?"":"(".$myItem->length.")");
	$myMysql .= " ".($myItem->attribute);
	$myMysql .= " ".($myItem->canBeNull?"NULL":"NOT NULL");
	$myMysql .= " ".($myItem->extra);
	$myMysql .=",";
	if ($myItem->index=="p"||$myItem->index=="pk"||$myItem->index=="primary"||$myItem->index=="primary key"){
		$PRIMARY.=$myItem->name.",";
	}
	if ($myItem->index=="u"||$myItem->index=="un"||$myItem->index=="unique"){
		$UNIQUE.=$myItem->name.",";
	}
	if ($myItem->index=="i"||$myItem->index=="in"||$myItem->index=="index"){
		$INDEX.=$myItem->name.",";
	}
	if ($myItem->fulltext){
		$FULLTEXT.=$myItem->name.",";
	}
}

if ($PRIMARY!="")
	$myMysql .= "\nPRIMARY KEY (".rtrim($PRIMARY,",")."),";
if ($UNIQUE!="")
	$myMysql .= "\nUNIQUE (".rtrim($UNIQUE,",")."),";
if ($FULLTEXT!="")
	$myMysql .= "\nFULLTEXT (".rtrim($FULLTEXT,",")."),";
if ($INDEX !="")
	$myMysql .= "\nINDEX (".rtrim($INDEX,",")."),";

$myMysql=rtrim($myMysql,",")."\n)\n";
echo $myMysql;
?>